#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
 package ${package}.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.oauth.components.client.application.ApplicationWidget;
import com.oauth.components.client.rpc.OAuthAsnyCallBack;
import ${package}.client.beans.HttpQueryString;
import ${package}.client.beans.YahooModel;
import ${package}.client.rpc.YahooRemoteService;
import ${package}.client.rpc.YahooRemoteServiceAsync;

public class TwitterPanel extends ApplicationWidget{
	public static final String applicationName = "Twitter" ;
	/**
	 * Create a remote service proxy to talk to the server-side Greeting service.
	 */
	private final YahooRemoteServiceAsync ${artifactId}Service = GWT
			.create(YahooRemoteService.class);

	 
	private LoginPanel mTwitterLoginPanel;
	
	private TwitterHomePanel mTwitterHomePanel;
	public TwitterPanel(){
		//setStackText(1,"<div class=${symbol_escape}"stackText${symbol_escape}">"+applicationName+"</div>",true);
		getElement().scrollIntoView();
		setWidth("100%");
	}
	
	public void initMainPanel(){
		String oauthVerifier = Window.Location.getParameter("oauth_verifier");
		HttpQueryString queryString = new HttpQueryString(oauthVerifier);
		${artifactId}Service.getYahooMails(queryString, new OAuthAsnyCallBack<YahooModel>() {
			
			public void onSuccess(YahooModel result) {
				if(result.isLoginView()){
					initLoginWidget();
				}else{
					initTweetsWidget(result);
				}
			} 

		});
	}
	
	
	public void initLoginWidget() {
		mTwitterLoginPanel = new LoginPanel(${artifactId}Service);
		add(mTwitterLoginPanel,"<div class=${symbol_escape}"stackText${symbol_escape}">"+applicationName+"</div>",true);
	}
	
	public void initTweetsWidget(YahooModel pTwitterModel) {
		mTwitterHomePanel = new TwitterHomePanel(pTwitterModel,${artifactId}Service);
		mTwitterHomePanel.initTwitterHomePanel();
		add(mTwitterHomePanel,"<div class=${symbol_escape}"stackText${symbol_escape}">"+applicationName+"</div>",true);
	}

	
}